/**
 * Copyright (C) 2012-2013 jumei, Inc.
 * ServiceConfigure.java
 * 2015年6月24日
 */
package com.goface.rpc.conf;

import java.util.HashMap;
import java.util.Map;

/**
 * @author jm110
 */
public class ServiceConfigure {

	public static final String SERVICE_TYPE = "service_type";// 用于判断服务端还是客户端
	public static final String SERVICE_TYPE_CLIENT = "rpc:client";
	public static final String SERVICE_TYPE_SERVER = "rpc:server";
	public static final String SERVICE_ID = "id";

	// 客户端配置
	public static final String SERVICE_CLIENT_INTF = "interface";
	public static final String SERVICE_CLIENT_ASYNC_INVOK = "async";
	public static final String SERVICE_CLIENT_OP_ONEWAY = "oneway";
	public static final String SERVICE_CLIENT_SERVICE_ADDRESS = "service_address";
	public static final String SERVICE_CLIENT_SERVICE_REF = "ref";

	// 服务端的配置
	public static final String SERVICE_SERVER_BINDING = "bind";
	public static final String DEFAULT_SERVICE_SERVER_BINDING = "localhost:5152";

	public static final String SERVICE_INVOKER = "service_invorker";

	/**
	 * @return the id
	 */
	public String getId() {
		return properties.get(SERVICE_ID).toString();
	}

	/**
	 * @return the properties
	 */
	public Map<String, Object> getProperties() {
		return properties;
	}

	public Object getProperty(String propertyKey) {
		return properties.get(propertyKey);
	}

	public void addProperty(String key, Object value) {
		properties.put(key, value);
	}

	public boolean isClientService() {
		return SERVICE_TYPE_CLIENT.equals(properties.get(SERVICE_TYPE)
				.toString());
	}

	public String getServiceRef() {
		Object ref = properties.get(SERVICE_CLIENT_SERVICE_REF);
		if (ref != null) {
			return ref.toString();
		}
		return null;
	}

	public String getServiceBinding() {
		Object serverBinding = properties.get(SERVICE_SERVER_BINDING);
		if (serverBinding == null) {
			return DEFAULT_SERVICE_SERVER_BINDING;
		}
		return serverBinding.toString();
	}

	// (serviceName,Properties)
	private Map<String, Object> properties = new HashMap<>();;

}
